import request from '@/utils/request.js'
// 接口方法, 只负责调用一个接口, 返回一个Promise对象
export const allChannelListAPI = () => {
  return request({
    url: '/v1_0/channels'
  })
}

// 用户 - 登录
export const loginAPI = ({ mobile, code }) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}
export const userChannelAPI = (channels) => {
  return request({
    url: '/v1_0/user/channels'
  })
}
export const ArticleListAPI = ({ channelId, timestamp }) => {
  return request({
    url: '/v1_0/articles',
    params: {
      channel_id: channelId,
      timestamp: timestamp || (new Date()).getTime()
    }
  })
}
export const articleDislikeAPI = ({ target }) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target
    }

  })
}
export const articleReportsAPI = ({ target, type, remark }) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'POST',
    data: {
      target, type, remark
    }

  })
}
export const updateChannelAPI = (channels) => {
  return request({
    url: '/v1_0/channels',
    method: 'PUT',
    data: { channels }
  })
}
export const suggestListAPI = ({ q }) => {
  return request({
    url: '/v1_0/suggestion',
    params: { q }
  })
}
export const searchResultAPI = ({ q, page = 1 }) => {
  return request({
    url: '/v1_0/search',
    params: {
      q, page
    }
  })
}
export const articleDetailAPI = ({ id }) => {
  return request({
    url: `/v1_0/articles/${id}`,
    method: 'GET'
  })
}
// 关注
export const followedUserAPI = ({ target }) => {
  return request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target
    }
  })
}
// 取关
export const unFollowedUserAPI = ({ uid }) => {
  return request({
    url: '/v1_0/user/followings/:target',
    method: 'DELETE',
    data: {
      uid
    }
  })
}
// 点赞
export const articleLikeAPI = ({ target }) => {
  return request({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target
    }
  })
}
// 取消点赞
export const articleDisLikeAPI = ({ artId }) => {
  return request({
    url: '/v1_0/article/likings/:target',
    method: 'DELETE',
    data: {
      artId
    }
  })
}
// 评论 - 获取列表
export const commentListAPI = ({ artId, offset = null, limit = 10 }) => {
  return request({
    url: '/v1_0/comments',
    params: {
      type: 'a', source: artId, offset, limit
    }
  })
}
// 评论 - 喜欢
export const commentLikingAPI = ({ comId }) => {
  return request({
    url: '/v1_0/comment/likings',
    method: 'POST',
    data: {
      target: comId
    }
  })
}
// 评论-取消喜欢
export const commentDisLikingAPI = ({ comId }) => {
  return request({
    url: `/v1_0/comment/likings/${comId}`,
    method: 'DELETE'
  })
}
// 发布评论
export const sendCommentAPI = ({ artId, content }) => {
  return request({
    url: '/v1_0/comments',
    method: 'POST',
    data: {
      target: artId,
      content: content
    }
  })
}
// 用户 - 基本资料
export const userInfoAPI = () => {
  return request({
    url: '/v1_0/user'
  })
}
